package com.rc.evcharger.common.type;


import com.rc.evcharger.common.utils.DataUtil;

import java.lang.reflect.Field;

public class ElectricizeControl extends BaseType implements DataType {
    String gunNum; // 1：A枪 2：B枪
    String startStatus; // 启动状态 2：充电开始3：停止充电
    String orderNum; // 00+手机号+四位流水号
    String obligate = "00 00 00 00";

    public ElectricizeControl() {
        super();
    }

    // 后台控制充电启停中，测量点0,1,2,3对应帧结构中的测量点号1,2,4,8，枪号0,1,2,3(珠海生产的)
    public ElectricizeControl(String gunNum, Integer startStatus, String orderNum) {
        StringBuffer sb = new StringBuffer();
        if (gunNum.length() < 2) {
            sb.append("0").append(gunNum);
            this.gunNum = sb.toString();
        } else {
            this.gunNum = gunNum;
        }

        this.startStatus = "0" + startStatus;
        this.orderNum = frameOrderNum(orderNum);
    }

    /**
     * @return
     */
    private String frameOrderNum0(String orderNum) {
        char[] c = orderNum.toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < c.length; i++) {
            sb.append("0").append(c[i]).append(DataUtil.SPLIT);
        }
        return sb.toString().trim();
    }

    /**
     * @return
     */
    private String frameOrderNum(String orderNum) {
        char[] c = orderNum.toCharArray();
        StringBuilder sb = new StringBuilder();
//        for (int i = 0; i < c.length; i++) {
//            if (i == 2) {
//                break;
//            }
//            sb.append("0").append(c[i]).append(DataUtil.SPLIT);
//        }
        for (int i = 0; i < c.length; i = i + 2) {
            sb.append(c[i]).append(c[i + 1]).append(DataUtil.SPLIT);
        }
        //sb.append("00");
        return sb.toString().trim();
    }

    public String getGunNum() {
        return gunNum;
    }

    public void setGunNum(String gunNum) {
        this.gunNum = gunNum;
    }

    public String getStartStatus() {
        return startStatus;
    }

    public void setStartStatus(String startStatus) {
        this.startStatus = startStatus;
    }

    public String getObligate() {
        return obligate;
    }

    public void setObligate(String obligate) {
        this.obligate = obligate;
    }

    public String getOrderNum() {
        return orderNum;
    }

    public void setOrderNum(String orderNum) {
        this.orderNum = orderNum;
    }

    @Override
    public boolean customField(Field field, StringBuffer sb) {
        return false;
    }
}
